Skip to content

Conversation

Eliekhoury17
Copy link

This pull request implements the codemod to replace deprecated zlib.bytesRead
with zlib.bytesWritten in Node.js transform streams, addressing DEP0108 (#196).

Changes included:

  • Updated the codemod workflow to track zlib stream variables and function parameters.
  • Added tests for assigned variables, destructured imports, and trackStreamProgress.
  • Updated README.md and package.json metadata.
  • Ensured all tracked usages of .bytesRead are replaced correctly.

This PR is part of the feature branch feat/bytesread-to-bytesWritten.

Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WOW good for first issue 🎉, there are some thing to adjust but on logic/approach it's good for me.
The readme is cool IMO.

There are a missing part which is the dynamic import (also missing on the issue spec my bad 😅).
@brunocroh for that do the resolve binding already work with dynamic import ?

// In CommonJS

async function main() {
    const zlib = await import("node:zlib");

    const gzip = zlib.createGzip();
    const processed = gzip.bytesWritten;
}

main();

// or in ESM
const zlib = await import("node:zlib");

const gzip = zlib.createGzip();
const processed = gzip.bytesWritten;

for the red ci you just have to resolve the new npm workspace on the monorepo for that just run npm I 👍

@AugustinMauroy AugustinMauroy added the awaiting author Reviewer has requested something from the author label Oct 6, 2025
@AugustinMauroy AugustinMauroy requested a review from Copilot October 6, 2025 12:35
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a Node.js codemod to migrate from the deprecated zlib.bytesRead property to zlib.bytesWritten as part of DEP0108 deprecation handling. The codemod automatically transforms zlib stream usage across various import patterns and variable declarations.

  • Implements comprehensive AST transformation logic to track zlib stream variables and replace deprecated property access
  • Adds extensive test coverage for different import patterns (CommonJS, ESM, destructured, dynamic) and variable declarations
  • Includes documentation and package configuration for the new codemod

Reviewed Changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/workflow.ts Core transformation logic with import tracking, variable resolution, and property replacement
workflow.yaml Workflow configuration defining the AST transformation step
tests/input/*.js Test input files covering various zlib usage patterns
tests/expected/*.js Expected transformation outputs for test validation
package.json Package metadata and dependencies for the codemod
codemod.yaml Codemod registry configuration and metadata
README.md Documentation with examples and usage instructions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow impressive. That nice some small review

Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WOW impressive first contribution. For me everything is covered.

I hope you enjoyed this contribution.

@AugustinMauroy AugustinMauroy requested a review from a team October 6, 2025 13:33
@AugustinMauroy AugustinMauroy added awaiting reviewer Author has responded and needs action from the reviewer and removed awaiting author Reviewer has requested something from the author labels Oct 6, 2025
}

// 1.b Handle dynamic imports: `await import("node:zlib")`
const dynamicImports = rootNode.findAll({ rule: { pattern: "const $$$VAR = await import($$$MODULE)" } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You just need to use $$$(Triple dollar sign) when more than on values will be found, in both case, just one will be existing so it needs to be written with $

const dynamicImports = rootNode.findAll({ rule: { pattern: "const $VAR = await import($MODULE)" } });

btw, I think we have an utility that can resolve dynamic imports already, and this usage is not covering all cases, by example, if this line starts with var or let this not will match already.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find the utility that can resolve dynamic imports but I have covered the rest of the cases for let and var and replaced the $$$ with $ .

I committed the changes.

Copy link
Author

@Eliekhoury17 Eliekhoury17 Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not resolve convesation. If you know if the utility that can resolve dynamic imports exists and how can I import it, I can use it and modify my code. If not, what i committed work very well and we can keep this version of the code and in this case, I will or if you can resolve conversation.

Copy link
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🙌

Comment on lines +15 to +33
Before:

```js
const zlib = require("node:zlib");
const gzip = zlib.createGzip();
gzip.on("end", () => {
console.log("Bytes processed:", gzip.bytesRead);
});
```

After:

```js
const zlib = require("node:zlib");
const gzip = zlib.createGzip();
gzip.on("end", () => {
console.log("Bytes processed:", gzip.bytesWritten);
});
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexbit-codemod what was the verdict about diff fenced blocks?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JakobJingleheimer FYI I asked for that on codemod slack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviewer Author has responded and needs action from the reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants